package cn.new18.testactivitytask.utils;

/**
 * Created by RaoWei on 2016/12/26 18:02.
 */

public class MyRect {
    private int l;
    private int r;
    private int t;
    private int b;
    private int width;
    private int hight;

    public MyRect(){}

    public MyRect(int l, int t, int r, int b){
        this.l = l;
        this.t = t;
        this.r = r;
        this.b = b;
        this.width = r - l;
        this.hight = b - t;
    }

    public MyRect(int width, int hight){
        this.width = width;
        this.hight = hight;
        this.l = 0;
        this.t = 0;
        this.r = width;
        this.b = hight;
    }

    public void set(int l, int t, int r, int b){
        this.l = l;
        this.t = t;
        this.r = r;
        this.b = b;
    }
    public void set(int l, int t){
        this.l = l;
        this.t = t;
        this.r = l + width;
        this.b = t + hight;
    }

    public boolean contains(MyRect rect) {
        if (l <= rect.l && t <= rect.t && r >= rect.r && b >= rect.b) {
            return true;
        }
        return false;
    }

    public boolean intersect(MyRect rect) {
        if (l > rect.r || t > rect.b || r < rect.l || b < rect.t) {
            return false;
        }
        if (l < rect.l && t < rect.t && r > rect.r && b > rect.b) {
            return false;
        }
        return true;
    }


    @Override
    public String toString() {
        return "l = " + l + ", t = " + t + ", r = " + r + ", b = " + b;
    }
}
